<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>图书管理系统</title>
<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
<!-- 引入css -->
<link href="css/bootstrap.min.css" rel="stylesheet" />
<!-- 使用bootstrap前端框架，首先引入jquery -->
<script type="text/javascript" src="/js/jquery-3.3.1.js"></script>
<!-- 引入js插件 -->
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript">
	function doOut(){
		var flag = confirm("是否确认注销？");
		if(flag){
			window.location="LoginServlet?flag=doOut";
		}
	}
	function doDelete(bookNo){
		var flag = confirm("是否确认删除？");
		if(flag){
			window.location="BookServlet?method=deleteBook&bookNo="+bookNo;
		}
	}
</script>
</head>
<body style="background:url('images/bg5.jpg');background-size:cover;">

	<div class="container">
	欢迎您，${user1.name }&nbsp;&nbsp;<a href="javascript:doOut()">注销</a><br>
	<c:if test="${user1.role==1 }">
		<button onclick="javascript:window.location='add.jsp'">添加雇员</button><br>
	</c:if>
	<!-- url标签有跳转功能无需form表单跳转 -->
	<form action="BookServlet?method=getAllBook" method="post">
		书名：<input name="bookName" value="${bookName }">
		作者：<input name="bookAuthor" value="${bookAuthor }">
		最初出版日期：<input name="startBookDate" class="Wdate" onClick="WdatePicker()" value="${startBookDate }">
		最后出版日期：<input name="endBookDate" class="Wdate" onClick="WdatePicker()" value="${endBookDate }">
		<input type="submit" value="查询">
		</form>
		
		<table border="1" class="table table-striped">
		<tr>
			<th>序号</th>
			<th>编号</th>
			<th>书名</th>
			<th>作者</th>
			<th>出版日期</th>
			<th>图书描述</th>
			<c:if test="${user1.role==1 }">
			<th>操作</th>
			</c:if>
		</tr>
		<c:forEach items="${list }" var="book" varStatus="status">
		<tr>
		<c:set value="${i+1 }" var="i"></c:set>
			<td>${i}</td>
			<td>${book.bookNo }</td>
			<td>${book.bookName }</td>
			<td>${book.bookAuthor }</td>
			<td>${book.bookDate }</td>
			<td>${book.bookDescription }</td>
			<c:if test="${user1.role==1 }">
			<td>
				<a href="BookServlet?method=getBookByNo&bookNo=${book.bookNo }">修改</a>&nbsp;&nbsp;
				<a href="javascript:doDelete(${book.bookNo })">删除</a>
			</td>
			</c:if>
		</tr>
		</c:forEach>
	</table>
	
	<c:url value="BookServlet?method=getAllBook" var="first">
		<c:param name="pageIndex" value="1"></c:param>
		<c:param name="bookName" value="${bookName }"></c:param>
		<c:param name="bookAuthor" value="${bookAuthor }"></c:param>
		<c:param name="bookDate" value="${bookDate }"></c:param>
	</c:url>
	
	<c:url value="BookServlet?method=getAllBook" var="forward">
		<c:param name="pageIndex" value="${pageIndex-1 }"></c:param>
		<c:param name="bookName" value="${bookName }"></c:param>
		<c:param name="bookAuthor" value="${bookAuthor }"></c:param>
		<c:param name="bookDate" value="${bookDate }"></c:param>
	</c:url>
	
	<c:url value="BookServlet?method=getAllBook" var="next">
		<c:param name="pageIndex" value="${pageIndex+1 }"></c:param>
		<c:param name="bookName" value="${bookName }"></c:param>
		<c:param name="bookAuthor" value="${bookAuthor }"></c:param>
		<c:param name="bookDate" value="${bookDate }"></c:param>
	</c:url>
	
	<c:url value="BookServlet?method=getAllBook" var="last">
		<c:param name="pageIndex" value="${totalPage }"></c:param>
		<c:param name="bookName" value="${bookName }"></c:param>
		<c:param name="bookAuthor" value="${bookAuthor }"></c:param>
		<c:param name="bookDate" value="${bookDate }"></c:param>
	</c:url>
	<a href="${first }">首页</a>
	<!-- 当前页码等于1时隐藏"上一页" -->
	<c:if test="${pageIndex > 1 }">
	<a href="${forward }">上一页</a>
	</c:if>
	<!-- 当前页码为总页码时，隐藏"下一页" -->
	<c:if test="${pageIndex < totalPage }">
	<a href="${next }">下一页</a>
	</c:if>
	<a href="${last }">尾页</a>
	</div>
</body>
</html>